package com.lagou.config;

import org.apache.catalina.Context;
import org.apache.catalina.Host;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;


/**
 * @author DingYiYuan
 * @description SpringApplication
 * @time 2021/4/25 20:38
 */
public class SpringApplication {



    /**
     * @description 创建tomcat实例
     * @author DingYiYuan
     * @time 2021/4/26 19:30
     */
    public static void run() {

        try {
            Tomcat tomcat = new Tomcat();
            Connector connector = tomcat.getConnector();
            connector.setPort(8080);
            connector.setURIEncoding("UTF-8");
            Host host = tomcat.getHost();
            host.setAppBase("webapps");
            Context context = tomcat.addWebapp("/", System.getProperty("user.dir"));
            context.addLifecycleListener(new Tomcat.FixContextListener());
            tomcat.start();
            tomcat.getServer().await();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }



}
